/*
 * IndividualInfoPanel.cpp
 *
 *  Created on: 09-01-2011
 *      Author: Przemek
 */

#include "customUI/IndividualInfoPanel.hpp"
#include "gui/Label.hpp"
#include "utils/MathUtils.hpp"
#include "listener/IndividualInfoSynchronizator.hpp"
#include "pch.hpp"
using namespace boost;
using namespace std;

IndividualInfoPanel::IndividualInfoPanel(float parentWidth, Individual* selected) :
	selected(selected)
{
	createComponents(parentWidth);

	IndividualInfoSynchronizator* individualInfoSynchronizator = new IndividualInfoSynchronizator(
			selected, hungerSlider, thirstSlider, libidoSlider, lifeSlider, angleSlider);
	hungerSlider->addManagedMouseListener(individualInfoSynchronizator);
	thirstSlider->addMouseListener(individualInfoSynchronizator);
	libidoSlider->addMouseListener(individualInfoSynchronizator);
	lifeSlider->addMouseListener(individualInfoSynchronizator);
	angleSlider->addMouseListener(individualInfoSynchronizator);
}

string IndividualInfoPanel::getSelectionName() const
{
	return "Individual";
}

const Individual* IndividualInfoPanel::getSelected() const
{
	return selected;
}

void IndividualInfoPanel::updateFromSelection()
{
	const State& state = getSelected()->getState();

	hungerSlider->setValue(static_cast<int> (state.getHungerValue()));
	thirstSlider->setValue(static_cast<int> (state.getThirstValue()));
	libidoSlider->setValue(static_cast<int> (state.getLibidoValue()));
	lifeSlider->setValue(static_cast<int> (state.getLifeValue()));
	angleSlider->setValue(static_cast<int> (MathUtils::trimToPositiveDegrees(MathUtils::toDegreeses(
			state.getLookDirection().getAngleInRadians()))));
}

void IndividualInfoPanel::createComponents(float parentWidth)
{
	static const float lineHeight = 20;
	const Dimension halfLineSize(parentWidth / 2.0f, lineHeight);

	float y = 0.0f;
	Label* label = new Label("Hunger:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	hungerSlider = new Slider(Range<int> (0, static_cast<int> (State::HUNGER_MAX_VALUE)));
	hungerSlider->setPosition(Vector(halfLineSize.getWidth(), y));
	hungerSlider->setSize(halfLineSize);
	add(hungerSlider);

	y += lineHeight;
	label = new Label("Thirst:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	thirstSlider = new Slider(Range<int> (0, static_cast<int> (State::THIRST_MAX_VALUE)));
	thirstSlider->setPosition(Vector(halfLineSize.getWidth(), y));
	thirstSlider->setSize(halfLineSize);
	add(thirstSlider);

	y += lineHeight;
	label = new Label("Libido:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	libidoSlider = new Slider(Range<int> (0, static_cast<int> (State::LIBIDO_MAX_VALUE)));
	libidoSlider->setPosition(Vector(halfLineSize.getWidth(), y));
	libidoSlider->setSize(halfLineSize);
	add(libidoSlider);

	y += lineHeight;
	label = new Label("Life:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	lifeSlider = new Slider(Range<int> (0, static_cast<int> (State::LIFE_MAX_VALUE)));
	lifeSlider->setPosition(Vector(halfLineSize.getWidth(), y));
	lifeSlider->setSize(halfLineSize);
	add(lifeSlider);

	y += lineHeight;
	label = new Label("Angle:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	angleSlider = new Slider(Range<int> (0, MathUtils::FULL_CIRCLE_DEGREESES - 1));
	angleSlider->setPosition(Vector(halfLineSize.getWidth(), y));
	angleSlider->setSize(halfLineSize);
	add(angleSlider);

	setSize(Dimension(parentWidth, y + lineHeight));
}
